package com.yanqu.road.server.cmd.banquet;

import com.yanqu.road.entity.banquet.cross.CrossBanquetMember;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.banquet.CrossBanquetProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.banquet.CrossBanquetMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.C_CROSS_JOIN_BANQUET, desc = "加入跨服宴会")
public class JoinBanquetCmd extends CrossCommand {


    private long userId;
    private String banquetId;
    private int giftId;
    private int titleAdd;
    private int patronsSkillAdd;
    private UserBaseInfo userBaseInfo;
    private long beginShowTime = Long.MAX_VALUE;
    private int giftAcceptState;
    private int autoJoinState;
    private int acId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossBanquetProto.JoinCrossBanquetReq reqMsg = CrossBanquetProto.JoinCrossBanquetReq.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        banquetId = reqMsg.getBanquetId();
        giftId = reqMsg.getGiftId();
        titleAdd =reqMsg.getTitleAdd();
        patronsSkillAdd = reqMsg.getPatronsSkillAdd();
        userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getPlayerBaseData());
        beginShowTime = reqMsg.getEndTime();
        giftAcceptState = reqMsg.getGiftAcceptState();
        autoJoinState = reqMsg.getGiftAutoState();
        acId = reqMsg.getAcId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossBanquetProto.JoinCrossBanquetResp.Builder respMsg =
                CrossBanquetMgr.joinBanquet((int)serverId,userId,
                        banquetId,giftId,titleAdd,patronsSkillAdd,userBaseInfo, beginShowTime, giftAcceptState,autoJoinState,acId);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_BANQUET_CROSS_JOIN_RESP, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
